import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const Home = () => import("@/pages/home");
const SongDetail = () => import("@/pages/song_detail");
const LoginSelect = () => import("@/pages/login_select");
const LoginConfirm = () => import("@/pages/login_confirm");
const Register = () => import("@/pages/register");
const Nickname = () => import("@/pages/nickname");
const Captcha = () => import("@/pages/captcha");
const ResetPwd = () => import("@/pages/reset_pwd");
const ResetCaptcha = () => import("@/pages/reset_captcha");
const LoginMail = () => import("@/pages/login_mail");
const Playlist = () => import("@/pages/playlist");
const PlaylistTag = () => import("@/pages/playlist_tag");
const PlaylistItem = () => import("@/pages/playlist_item");
const MailNickname = () => import("@/pages/mail_nickname");
const Rank = () => import("@/pages/rank");
const Recommend = () => import("@/pages/recommend");
const CommentMusic = () => import("@/pages/comment_music");
const CommentHot = () => import("@/pages/comment_hot");
const Artist = () => import("@/pages/artist");

export default new Router({
  routes: [{
      path: '/',
      redirect: {
        name: "Home"
      },
      meta: {
        keepAlive: false // 不需要被缓存
      }
    },
    {
      path: '/home',
      name: 'Home',
      component: Home,
      meta: {
        keepAlive: true // 需要被缓存
      }
    },
    {
      path: '/song_detail',
      name: 'SongDetail',
      component: SongDetail,
      meta: {
        keepAlive: false // 不需要被缓存
      }
    },
    {
      path: '/login_select',
      name: 'LoginSelect',
      component: LoginSelect,
      meta: {
        keepAlive: true // 需要被缓存
      }
    },
    {
      path: '/login_confirm',
      name: 'LoginConfirm',
      component: LoginConfirm,
      meta: {
        keepAlive: false // 不需要被缓存
      }
    },
    {
      path: '/register',
      name: 'Register',
      component: Register,
      meta: {
        keepAlive: false // 不需要被缓存
      }
    },
    {
      path: '/nickname',
      name: 'Nickname',
      component: Nickname,
      meta: {
        keepAlive: false // 不需要被缓存
      }
    },
    {
      path: '/captcha',
      name: 'Captcha',
      component: Captcha,
      meta: {
        keepAlive: false // 不需要被缓存
      }
    },
    {
      path: '/reset_pwd',
      name: 'ResetPwd',
      component: ResetPwd,
      meta: {
        keepAlive: false // 不需要被缓存
      }
    },
    {
      path: '/reset_captcha',
      name: 'ResetCaptcha',
      component: ResetCaptcha,
      meta: {
        keepAlive: false // 不需要被缓存
      }
    },
    {
      path: '/login_mail',
      name: 'LoginMail',
      component: LoginMail,
      meta: {
        keepAlive: false // 不需要被缓存
      }
    },
    {
      path: '/playlist',
      name: 'Playlist',
      component: Playlist,
      meta: {
        keepAlive: true // 需要被缓存
      }
    },
    {
      path: '/playlist_tag',
      name: 'PlaylistTag',
      component: PlaylistTag,
      meta: {
        keepAlive: true // 需要被缓存
      }
    },
    {
      path: '/playlist_item',
      name: 'PlaylistItem',
      component: PlaylistItem,
      meta: {
        keepAlive: false // 不需要被缓存
      }
    },
    {
      path: '/mail_nickname',
      name: 'MailNickname',
      component: MailNickname,
      meta: {
        keepAlive: false // 不需要被缓存
      }
    },
    {
      path: '/rank',
      name: 'Rank',
      component: Rank,
      meta: {
        keepAlive: true // 需要被缓存
      }
    },
    {
      path: '/recommend',
      name: 'Recommend',
      component: Recommend,
      meta: {
        keepAlive: true // 需要被缓存
      }
    },
    {
      path: '/comment_music',
      name: 'CommentMusic',
      component: CommentMusic,
      meta: {
        keepAlive: false // 不需要被缓存
      }
    },
    {
      path: '/comment_hot',
      name: 'CommentHot',
      component: CommentHot,
      meta: {
        keepAlive: false // 不需要被缓存
      }
    },
    {
      path: '/artist',
      name: 'Artist',
      component: Artist,
      meta: {
        keepAlive: false // 不需要被缓存
      }
    },
  ]
})

// 解决replace跳转相同地址报错
const originalReplace = Router.prototype.replace;
Router.prototype.replace = function replace(location) {
  return originalReplace.call(this, location).catch(err => err)
};
// 解决push跳转相同地址报错
const originalPush = Router.prototype.push;
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
};
